package ls.jpa.chapterC.domain;

import ls.jpa.chapterC.base.AudiTableEntity;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.persistence.*;
import java.util.Collection;

/**
 * @author Barudisshu
 */
@Entity
@Table(name = "t_customer", schema = "", catalog = "db_test")
@AttributeOverride(name = "id", column = @Column(name = "cus_id", length = 32))
public class Customer extends AudiTableEntity {
    @Basic
    @Column(name = "cus_name")
    private String cusName;
    @Basic
    @Column(name = "cus_pwd")
    private String cusPwd;
    @Basic
    @Column(name = "cus_address", insertable = false, updatable = false)
    private Long cusAddress;
    @Basic
    @Column(name = "cus_project", insertable = false, updatable = false)
    private Long cusProject;

    @ManyToOne
    @JoinColumn(name = "cus_address", referencedColumnName = "address_id")
    private Address address;

    @OneToMany(mappedBy = "customer",fetch=FetchType.EAGER, cascade = CascadeType.ALL,targetEntity = Phone.class)
    private Collection<Phone> phones;

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "t_cp", joinColumns = @JoinColumn(name = "cp_project_id", referencedColumnName = "cus_id"),
            inverseJoinColumns = @JoinColumn(name = "cp_cus_id", referencedColumnName = "project_id"))
    private Collection<Project> projects;

    public String getCusName() {
        return cusName;
    }

    public void setCusName(String cusName) {
        this.cusName = cusName;
    }

    public String getCusPwd() {
        return cusPwd;
    }

    public void setCusPwd(String cusPwd) {
        this.cusPwd = cusPwd;
    }

    public Long getCusAddress() {
        return cusAddress;
    }

    public void setCusAddress(Long cusAddress) {
        this.cusAddress = cusAddress;
    }

    public Long getCusProject() {
        return cusProject;
    }

    public void setCusProject(Long cusProject) {
        this.cusProject = cusProject;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Collection<Phone> getPhones() {
        return phones;
    }

    public void setPhones(Collection<Phone> phones) {
        this.phones = phones;
    }

    public Collection<Project> getProjects() {
        return projects;
    }

    public void setProjects(Collection<Project> projects) {
        this.projects = projects;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
